#include <iostream>
#include <vector>
using namespace std;

vector<vector<int>> map;
int row, column;

// 请注意！题目条件有误，子矩阵一定是方阵
int isPerfectMatrix(int leftEdge, int upEdge, int rightEdge, int downEdge) {
    int numVote = 0;
    for (int i = leftEdge; i <= rightEdge; i++) {
        for (int j = upEdge; j <= downEdge; j++) {
            if ((i == leftEdge || i == rightEdge ||
            j == upEdge || j == downEdge)) {
                if (!map[j][i]) { return 0; }
            }
            else {
                numVote += map[j][i] ? 1 : -1;
            }
        }
    }

    if (abs(numVote) <= 1) { return 1; }
    return 0;
}

int getSumResult(int n, int m) {
    // 用三个循环嵌套来遍历
    int result = 0;
    for (int leftEdge = 0; leftEdge < column; leftEdge++) {
        for (int upEdge = 0; upEdge < row; upEdge++) {
            for (int width = 1; (leftEdge + width < column) &&
            (upEdge + width < row); width++) {
                result += isPerfectMatrix(leftEdge, upEdge, leftEdge + width, upEdge + width);
            }
        }
    }
    return result;
}

int main() {
    cin >> row >> column;
    map.resize(row, vector<int>());
    for (int i = 0; i < row; i++) {
        map[i].resize(column, 0);
        for (int j = 0; j < column; j++) {
            cin >> map[i][j];
        }
    }
    int result = getSumResult(row,column);
    cout << result;
    return 0;
}